<template>
	<div class="add-jq-dialog">
		
		<appdialog 
			ref="dialog"
			:visible="false" 
			title="版本升级"
			@confirm="confirmAdd"
			@cancle="cancleAdd"
			width="40%"
			>
				<el-alert
			    :title="'当前版本:' + data.appVersion + ', 您确定将实例' + data.instName + '升级到所选版本？'"
			    type="info"
			    :closable="false"
			    show-icon>
			  </el-alert>
			  
				<el-form ref="addForm"  
								:rules="rules" 
                :model="addForm"
                label-width="80px">

        <el-form-item label="版本：" prop="templateId">
         	<version-select ref="versionSelect" @change="(name,v)=>{this.addForm.templateId=v}"></version-select>
        </el-form-item>
            
      </el-form>
      
      <!--<el-row>
				<el-col :span="10"></el-col>
				<el-col :span="3">
					
				</el-col>
				<el-col :span="2" :offset="5">
					<el-button type="danger" @click="handleUpleve">升级</el-button>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="24" style="height:300px;">
            <el-card style="width:100%;background:#000;height:300px;color:#fff;" v-show="isShow">
            
			    	</el-card>
				</el-col>
			</el-row>-->
			
			
		</appdialog>
		
		
		
	</div>
</template>

<script>


import appdialog from "@/view/components/dialog/dialog";
import versionSelect from '@/view/components/select/versonSelect.vue';
import {upgrade} from "@/service/swagger/InstanceController"


export default {
	name: "uplevedialog",
	components: {
		appdialog,
		versionSelect
	},
	data() {
    return{
      isShow:false,
      id : "", // 实例id
      data : {},
      addForm : {
      	templateId :"",
      },
      rules : {
      	templateId: [
          { required: true, message: '请选择升级版本', trigger: 'blur' },
        ],
      }
    }
  },
  mounted() {
  	
  },
	methods:{
		init(data){
			// 实例id
			if(data&&data.id){
				this.data = data ;
				this.id = data.instId;
			}
			setTimeout(()=>{
				this.$refs.versionSelect.reset().initData(this.id)
			},200)
			return this;
		},
		handleUpleve(){
      this.isShow=true
		},
   	open(){
   		
   		this.$refs.dialog.open();
   		return this;
		 },
		confirmAdd(){
			// 验证表单
   		this.$refs.addForm.validate((valid) => {
        if (valid) {
        	// 验证通过
          this.submitUpdate();
        } else {
        	setTimeout(()=>{
        		this.open();
        	},50)
          return false;
        }
      });
		},
		submitUpdate(){
			upgrade({
				sourceInstId : this.id ,
				templateId : this.addForm.templateId,
			}).then(ret=>{
				if(!ret.code){
					this.$emit("addSucess")
					this.$message({message: '请求成功，开始升级',type: 'success',duration : 2000,})
				}
			})
		},
   	cancleAdd(){
   		
   	},
	}
}
</script>

<style scoped lang="scss">
@import "../../../styles/variables.scss";


</style>